package com.zyd.blog.personal.controller;

import com.zyd.blog.personal.service.BigPlotformService;
import com.zyd.blog.personal.utils.RespResultUtils;
import com.zyd.blog.personal.vo.ApplyDesignSettleVo;
import com.zyd.blog.personal.vo.ResponseResultVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 设计师申请
 * @author mfy
 */
@RestController
@RequestMapping("/plotform")
public class DesignerController {

    @Resource
    private BigPlotformService bigPlotformService;

    /**
     *  设计师申请入驻
     *  访问路径    http://localhost:8443/plotform/applyDesign
     * @param applyDesignSettleVo 提交信息实体对象
     * @return     操作结果
     */
    @RequestMapping("/applyDesign")
    public ResponseResultVo applyDesign(ApplyDesignSettleVo applyDesignSettleVo){
        if(applyDesignSettleVo.getUserId() == null){
            return RespResultUtils.getFailResult("用户id不能为空");
        }
        try{
            int res = bigPlotformService.applyDesign(applyDesignSettleVo);
            switch (res){
                case -1:
                    return RespResultUtils.getFailResult("用户id不能为空");
                case 0:
                    return RespResultUtils.getSuccessBoolean("申请提交成功");
                case 2:
                    return RespResultUtils.getFailResult("已提交申请待审核");
                case 3:
                    return RespResultUtils.getFailResult("您已经是设计师,无需重复申请");
                default:
                    return RespResultUtils.getFailResult("申请提交失败");
            }
        }catch (RuntimeException e){
            return RespResultUtils.getFailResult("申请失败");
        }
    }

    /**
     *  修改设计师申请入驻
     *  访问路径    http://localhost:8443/plotform/updateDesign
     * @param applyDesignSettleVo 提交信息实体对象
     * @return     操作结果
     */
    @RequestMapping("/updateDesign")
    public ResponseResultVo updateDesign(ApplyDesignSettleVo applyDesignSettleVo){
        if(applyDesignSettleVo.getUserId() == null){
            return RespResultUtils.getFailResult("用户id不能为空");
        }
        try{
            int res = bigPlotformService.updateDesign(applyDesignSettleVo);
            switch (res){
                case -1:
                    return RespResultUtils.getFailResult("用户id不能为空");
                case 0:
                    return RespResultUtils.getSuccessBoolean("申请修改成功");
                default:
                    return RespResultUtils.getFailResult("申请修改失败");
            }
        }catch (RuntimeException e){
            return RespResultUtils.getFailResult("申请修改失败");
        }
    }

    /**
     * 得到用户申请信息
     * 访问路径 http://localhost:8443/plotform/getApplyInfo?userId=1
     * @param userId    用户id
     * @return  申请信息
     */
    @RequestMapping("/getApplyInfo")
    public ResponseResultVo getApplyInfo(Long userId){
        if(userId == null){
            return RespResultUtils.getFailResult("用户id不能为空");
        }
        return RespResultUtils.getSuccessData(bigPlotformService.getApplyInfo(userId));
    }

    /**
     * 第一次查看申请成功信息
     * 访问路径 http://localhost:8443/plotform/fristSee?userId=1
     * @param userId    用户id
     * @return  设计师申请信息
     */
    @RequestMapping("/fristSee")
    public ResponseResultVo fristSee(Long userId){
        if(userId == null){
            return RespResultUtils.getFailResult("用户id不能为空");
        }
        if(bigPlotformService.fristSee(userId)){
            return RespResultUtils.getSuccessBoolean("首次查看成功");
        }else{
            return RespResultUtils.getFailResult("首次查看失败");
        }
    }


}
